﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web.Hosting;

namespace CoreEx.Wcf.Server
{
    public class VirtualSvcFile : VirtualFile
    {
        private readonly string _serviceName;

        public VirtualSvcFile(string virtualPath, string serviceName)
            : base(virtualPath)
        {
            _serviceName = serviceName;
        }


        public override Stream Open()
        {
            var memoryStream = new MemoryStream();
            var streamWriter = new StreamWriter(memoryStream);
            string template =
                "<%@ ServiceHost Language=\"C#\" Debug=\"true\" Service=\"{0}\" Factory = \"{1}\" %>";

            string svc = string.Format(template, _serviceName, typeof(ServiceContainerServiceHostFactory).FullName);
            streamWriter.Write(svc);
            streamWriter.Flush();
            memoryStream.Seek(0, SeekOrigin.Begin);
            return memoryStream;
        }


    }
}
